<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//用户资金明细表
class Withdraw_list_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'withdraw_list';
        $this->withdraw_order = 'withdraw_order';
        $this->users = 'users';
    }
    
    function get($where){
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array();
    }
    
    function get_order_list($where,$page,$limit){
        $this->db->select($this->table.'.*,'.$this->users.'.username,'.$this->users.'.parent_id');
        $this->db->from($this->table);
        $this->db->join($this->users,$this->users.'.user_id = '.$this->table.'.user_id');
        $this->db->where($where);
        $this->db->order_by('id','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_order($where){
        $this->db->select('*');
        $this->db->from($this->withdraw_order);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array();
    }
    
    function get_list($where,$page,$limit){
        $this->db->select($this->table.'.*,'.$this->users.'.username');
        $this->db->from($this->table);
        $this->db->join($this->users,$this->users.'.user_id = '.$this->table.'.user_id');
        $this->db->where($where);
        $this->db->order_by('id','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_count($where){
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->num_rows();
    }
     //获取额
    function get_total_count($where){
        $this->db->select('SUM(amount) amount,SUM(fee) fee,SUM(finance) finance');
        $this->db->from($this->table);
        $this->db->where($where);
        if($where_in){
            $this->db->where_in($this->table.'.user_id',$where_in);
        }
        $this->db->order_by('id','desc');
        return $this->db->get()->row_array();
    }
    
    function update($data,$order_nid){
        return $this->db->where('order_nid',$order_nid)->update($this->table, $data);
    }
}
